package com.wly.ui.panel
{
	import com.wly.datapool.tower.TowerInfo;
	import com.wly.ui.common.ProgressBar;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class TowerInfoPanel extends MovieClip
	{
		private var _tfName:TextField;
		private var _tfLevel:TextField;
		private var _tfArea:TextField;
		private var _tfSpeed:TextField;
		private var _tfAttack:TextField;
		private var _mcExp:ProgressBar;
		private var _btnClose:SimpleButton;
		private var _btnSell:SimpleButton;
		private var _btnUpgrade:SimpleButton;
		
		private var _tower:TowerInfo;
		
		public function TowerInfoPanel()
		{
			super();
			
			_tfName   = getChildByName("tfName") as TextField;
			_tfLevel  = getChildByName("tfLevel") as TextField;
			_tfArea   = getChildByName("tfArea") as TextField;
			_tfSpeed  = getChildByName("tfSpeed") as TextField;
			_tfAttack = getChildByName("tfAttack") as TextField;
			_mcExp    = getChildByName("mcExp") as ProgressBar;
			
			_btnClose = getChildByName("btnClose") as SimpleButton;
			_btnClose.addEventListener(MouseEvent.CLICK, onClose);
			
			_btnSell  = getChildByName("btnSell") as SimpleButton;
			_btnSell.addEventListener(MouseEvent.CLICK, onSell);
			
			_btnUpgrade = getChildByName("btnUpgrade") as SimpleButton;
			_btnUpgrade.addEventListener(MouseEvent.CLICK, onUpgrade);
		}
		
		private function onClose(e:MouseEvent):void
		{
			if(_tower)
			{
				_tower.destortPanel();
			}
		}
		
		private function onSell(e:MouseEvent):void
		{
			if(_tower)
			{
				_tower.doSell();
			}
		}
		
		private function onUpgrade(e:MouseEvent):void
		{
			if(_tower)
			{
				_tower.doUpgrade();
			}
		}
		
		public function destory():void
		{
			
		}
		
		public function updateData(tower:TowerInfo):void
		{
			_tower = tower;
			_tfName.text    = _tower.baseInfo.name;
			_tfLevel.text   = _tower.level.toString();
			_tfArea.text    = _tower.attackArea.toString();
			_tfSpeed.text   = _tower.speed.toString();
			_tfAttack.text  = _tower.attack.toString();
			_mcExp.updateProgress(_tower.curExp, _tower.maxExp);
			if(!tower.baseInfo.nextTower || tower.curExp<tower.maxExp)
			{
				_btnUpgrade.visible = false;
			}
			else
			{
				_btnUpgrade.visible = true;
			}
		}
	}
}